//
//  SmsCloudCityController.m

#import "SmsCloudCityController.h"
#import "SmsCloudMainNavView.h"
#import "SmsCloudCityTableCell.h"
@interface SmsCloudCityController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic,strong) SmsCloudMainNavView *smsCloudCityNavView;
@property (nonatomic,strong) UITableView *smsCloudCityTableView;
@property (nonatomic, strong) NSArray * smsCloudCitys;
@end

@implementation SmsCloudCityController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.hidden = YES;
    self.view.backgroundColor = [SmsCloudHead SmsCloudColorHexString:@"#FFFFFF"];
    [self smsCloudInitView];
}
- (SmsCloudMainNavView *)smsCloudCityNavView{
    if(!_smsCloudCityNavView){
        __weak __typeof__(self) weakSelf = self;
        _smsCloudCityNavView = [[SmsCloudMainNavView alloc] init];
        _smsCloudCityNavView.backgroundColor = [SmsCloudHead SmsCloudColorHexString:@"#FFFFFF"];
        _smsCloudCityNavView.smsCloudNavTitle = @"选择国家";
        _smsCloudCityNavView.SmsCloudMainBackBlock = ^{
            [weakSelf.navigationController popViewControllerAnimated:true];
        };
    }
    return _smsCloudCityNavView;
}
- (UITableView *)smsCloudCityTableView{
    if(!_smsCloudCityTableView){
        _smsCloudCityTableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
        _smsCloudCityTableView.delegate = self;
        _smsCloudCityTableView.dataSource = self;
        _smsCloudCityTableView.backgroundColor = [UIColor clearColor];
        _smsCloudCityTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return _smsCloudCityTableView;
}
- (void)smsCloudInitView{
    [self.view addSubview:self.smsCloudCityNavView];
    [self.view addSubview:self.smsCloudCityTableView];

    [self.smsCloudCityNavView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@([SmsCloudHead SmsCloudScreewRatio:0]));
        make.right.equalTo(@([SmsCloudHead SmsCloudScreewRatio:0]));
        make.top.equalTo(@([SmsCloudHead SmsCloudScreewRatio:0]));
        make.height.equalTo(@([SmsCloudHead SmsCloudScreewRatio:88] + [SmsCloudHead SmsCloudTopSafeH]));
    }];
    [self.smsCloudCityTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@([SmsCloudHead SmsCloudScreewRatio:0]));
        make.right.equalTo(@([SmsCloudHead SmsCloudScreewRatio:0]));
        make.top.equalTo(@([SmsCloudHead SmsCloudScreewRatio:112] + [SmsCloudHead SmsCloudTopSafeH]));
        make.bottom.equalTo(@([SmsCloudHead SmsCloudScreewRatio:0]));
    }];
    
    self.smsCloudCitys = [SmsCloudDataHelper defaultMag].smsCloudCitys;
    [self.smsCloudCityTableView reloadData];
}
#pragma mark - UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.smsCloudCitys.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return [SmsCloudHead SmsCloudScreewRatio:88];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    SmsCloudCityTableCell *smsCloudCityTableCell = [SmsCloudCityTableCell smsCloudCityTableCell:tableView];
    smsCloudCityTableCell.smsCloudCityMdl = self.smsCloudCitys[indexPath.row];
    return smsCloudCityTableCell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    SmsCloudCityModel *smsCloudCityMdl = self.smsCloudCitys[indexPath.row];
    if (self.SmsCloudCityBlock) {
        self.SmsCloudCityBlock(smsCloudCityMdl);
        [self.navigationController popViewControllerAnimated:true];
    }
}
@end
